import { createRouter, createWebHashHistory } from 'vue-router'
import SysMenu from '@/components/SysMenu/index.vue'

const routes = [
  {
    path: '/',
    name: 'SysMenu',
    redirect: '/Home',
    component: SysMenu,
    children: [
      {
        path: '/Home',
        name: 'Home',
        component: () => import('@/views/HomeView/index.vue')
      }, {
        path: '/Student',
        name: 'StudentView',
        component: () => import('@/views/StudentView/index.vue')
      }, {
        path: '/Course',
        name: 'CourseView',
        component: () => import('@/views/CourseView/index.vue')
      }, {
        path: '/Sc',
        name: 'ScView',
        component: () => import('@/views/ScView/index.vue')
      }, {
        path: '/StudentScCourse',
        name: 'StudentScCourseView',
        component: () => import('@/views/StudentScCourseView/index.vue')
      }
    ]
  }, {
    path: '/404',
    name: '404',
    component: () => import('@/views/ErrorPage/404.vue')
  }, {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login/index.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  // 获取token
  if (!localStorage.getItem('token')) {
    if(to.path !== '/login'){
      next('/login')  
    }
  }
  next();
})
export default router
